// src/access.ts
export default function access(initialState: {
  currentUser?: API.AdminPassport | undefined;
}) {
  const { currentUser } = initialState || {};

  return {
    adminRouteFilter: (route: any) => {
      //   console.log('access.ts.initialState.currentUser:', currentUser);
      //   console.log('access.ts.route:', route);

      //没有配置key的直接放行，不做权限控制
      if (!route.key || route.key == '') {
        return true;
      }

      if (!currentUser) {
        return false;
      }

      if (currentUser.super) {
        return true;
      }

      const userRights = currentUser.funcRights || [];
      return userRights.indexOf(route.key) !== -1;
    },
  };
}
